<?
ob_start();
//============ Start Session และทำการเรียก Function ติดต่อฐานข้อมูล 
session_start();
require("connect/connect.php");
require("connect/function.php");

//============ เลือกข้อมูลส่วนตัวออกมาแสดง
$resultUser=select("member","where 1 and Email='".$_SESSION["strEmail"]."' ");
if(!$resultUser)
{
header("location:logout.php");
}

//============  ถ้าทำการแก้ไขข้อมูลส่วนตัว
if($_GET["action"]=="Register")
{
			//============ ตรวจสอบอีเมล์ป้องกันค่าว่าง
			$result=select("member","where 1 and (Email='".$_POST["txtEmail"]."'  and Email != '".$_SESSION["strEmail"]."' )");
			if($result)
			{
						echo "<script language=\"JavaScript\">";
						echo "alert('อีเมล์นี้มีคนใช้แล้ว');";
						echo "</script>";	
			}
			else
			{
				//============ แก้ไขข้อมูลส่วนตัว
					$sql="Update member set Email='".$_POST["txtEmail"]."',Password='".$_POST["txtPass"]."',Name='".$_POST["txtName"]."',LastName='".$_POST["txtLastName"]."',Gender='".$_POST["rdoGender"]."',Address='".$_POST["txtAddress"]."',Province='".$_POST["txtProvince"]."',ZipCode='".$_POST["txtZipCode"]."',Tel='".$_POST["txtTel"]."',Fax='".$_POST["txtFax"]."' where Email='".$_SESSION["strEmail"]."' ";
					$dbquery = mysql_query($sql);
					  
					  $_SESSION["strEmail"]=$_POST["txtEmail"];
					  $_SESSION["strPassword"]=$_POST["txtPass"];
					  session_write_close();

						echo "<script language=\"JavaScript\">";
						echo "alert('แก้ไขข้อมูลเรียบร้อยแล้ว');window.location='.';";
						echo "</script>";
											
			}
			
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<link rel="shortcut icon" href="../favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>ศูนย์หนังสืออิเล็กทรอนิค</title>
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
body {
	background-color: #ececec;
	background-image: url(../img/BGm1.png);
	background-repeat: repeat-x;
	margin-top: 0px;
}
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {font-family: "layiji MaHaNiYom BAO"}
.style3 {	color: #999999;
	font-family: Arial, Helvetica, sans-serif;
}
#apDiv1 {
	position:absolute;
	width:123px;
	height:75px;
	z-index:1;
	left: 122px;
	top: 477px;
}
-->
</style>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>
<table width="100%" height="838" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="0" height="149" align="center"><table width="900" height="146" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="49" height="149" rowspan="2" background="../img/BGtop_l.png">&nbsp;</td>
        <td width="246" rowspan="2" background="../img/BGtop.png"><img src="../img/logo.png" width="246" height="149" border="0" usemap="#Map2" /></td>
        <td width="564" height="65" valign="top" background="../img/BGtop.png"><table width="259" border="0" align="right" cellpadding="0" cellspacing="0">
          <tr>
            <td width="259" height="43" align="left" valign="top"><form id="form1" name="form1" method="post" action="">
              <br />
              <label>
              <input name="textfield" type="text" id="textfield" value="" size="10" />
              </label>
              <a href="#"><img src="../img/search.png" width="78" height="24" align="top" /></a>
            </form>            </td>
          </tr>
        </table>
          <p>&nbsp;</p></td>
        <td width="41" valign="top" background="../img/BGtop_r.png">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" valign="top"><img src="../img/button1.png" width="487" height="74" border="0" usemap="#Map3" 
        " /><img src="../img/button2.png" width="114" height="74" border="0" usemap="#Map4" /></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="top"><table width="900" height="506" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="50" height="19">&nbsp;</td>
        <td width="800">&nbsp;</td>
        <td width="50">&nbsp;</td>
      </tr>
      <tr>
        <td height="187" valign="top" background="../img/BGh_l.png">&nbsp;</td>
        <td align="center" valign="top" background="../img/BGh.png"><!-- InstanceBeginEditable name="EditRegion3" --><!-- InstanceEndEditable --></td>
        <td background="../img/BGh_r.png">&nbsp;</td>
      </tr>
      <tr>
        <td height="102" valign="top" bgcolor="#d0d2d5">&nbsp;</td>
        <td height="300" valign="top" bgcolor="#d0d2d5"><!-- InstanceBeginEditable name="EditRegion4" -->
		<table width="778" border="0" align="center" cellpadding="0" cellspacing="1" >
  <tr> 
    <td> <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr> 
                <td width="20%" valign="top"><br> </td>
                <td width="60%" valign="top"> 
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <!--DWLayoutTable-->
                    <tr> 
                      <td width="417" height="310" valign="top">
                          <script language="JavaScript">
						
	  
					   function CheckEmail(e) {
								ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPaSDFGHJKLzXCVBNM";
									for(i=0; i < e.length ;i++){
									if(ok.indexOf(e.charat(i))<0){ 
									return (false);
									}	
								} 
								if (document.images) {
								re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
								re_two = /^.+\@(\[?)[a-za-z0-9\-\.]+\.([a-za-z]{2,4}|[0-9]{1,3})(\]?)$/;
										if (!e.match(re) && e.match(re_two)) {
										return (-1);		
										} 
								}
						}
			
									
						  function checkvalue()
						  {
						  // ============ ตรวจสอบค่าว่าง
								  if(document.frmRegister.txtEmail.value=="")
								  {
								  alert('กรุณากรอก อีเมล์ ');
								  document.frmRegister.txtEmail.focus();
								  return false;
								  }
								  
								  
								  if(document.frmRegister.txtEmailCon.value=="")
								  {
								  alert('กรุณากรอก ยืนยันอีเมล์ ');
								  document.frmRegister.txtEmailCon.focus();
								  return false;
								  }
								  
								  if(document.frmRegister.txtEmail.value != document.frmRegister.txtEmailCon.value)
								  {
								  alert('กรุณายืนยันอีเมล์ให้ตรงกัน');
								  document.frmRegister.txtEmail.focus();
								  return false;
								  }
								  
								  if(document.frmRegister.txtPass.value=="")
								  {
								  alert('กรุณากรอก รหัสผ่าน ');
								  document.frmRegister.txtPass.focus();
								  return false;
								  }
								  
								  if(document.frmRegister.txtPassCon.value=="")
								  {
								  alert('กรุณากรอก ยืนยันรหัสผ่าน ');
								  document.frmRegister.txtPassCon.focus();
								  return false;
								  }
								  
								  if(document.frmRegister.txtPass.value != document.frmRegister.txtPassCon.value)
								  {
								  alert('กรุณายืนยันรหัสผ่านให้ตรงกัน');
								  document.frmRegister.txtPassCon.focus();
								  return false;
								  }
								  
								  if(document.frmRegister.txtName.value=="")
								  {
								  alert('กรุณากรอก ชื่อ ');
								  document.frmRegister.txtName.focus();
								  return false;
								  }
								  
								  if(document.frmRegister.txtLastName.value=="")
								  {
								  alert('กรุณากรอก นามสกุล');
								  document.frmRegister.txtLastName.focus();
								  return false;
								  }								  
								  								  
								  if(document.frmRegister.txtAddress.value=="")
								  {
								  alert('กรุณากรอก ที่อยู่ ');
								  document.frmRegister.txtAddress.focus();
								  return false;
								  }
								  
								  

								  if(document.frmRegister.txtProvince.value=="")
								  {
								  alert('กรุณากรอก จังหวัด ');
								  document.frmRegister.txtProvince.focus();
								  return false;
								  }								  
								  
								  
								  if(document.frmRegister.txtZipCode.value=="")
								  {
								  alert('กรุณากรอก รหัสไปรษณีย์ ');
								  document.frmRegister.txtZipCode.focus();
								  return false;
								  }
								  								  
								  if(document.frmRegister.txtTel.value=="")
								  {
								  alert('กรุณากรอก หมายเลขโทรศัพท์ ');
								  document.frmRegister.txtTel.focus();
								  return false;
								  }

						  }
						  </script>
                        <form name="frmRegister" method="post" action="" onSubmit="return checkvalue()">
                          <table width="445" border="0">
                            <tr> 
                              <td><table width="418" height="22" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
                                  <tr> 
                                    <td width="8"> <img src="image/menu01.jpg" width="8" height="22" alt=""></td>
                                    <td width="389" background="image/menu02.jpg"><div align="center"><strong>แก้ไขข้อมูลส่วนตัว</strong><strong></strong><strong> 
                                        </strong></div></td>
                                    <td width="9"> <img src="image/menu03.jpg" width="9" height="22" alt=""></td>
                                  </tr>
                                </table>
                                
                              </td>
                            </tr>
                            <tr> 
                              <td><div align="right">กรุณากรอกข้อมูลให้ครบตามช่องที่กำหนด 
                                  (<font color="#FF0000">*</font>) </div></td>
                            </tr>
                            <tr> 
                              <td> <table width="100%" border="0" cellspacing="2" cellpadding="2">
                                  <tr> 
                                    <td width="3%">&nbsp;</td>
                                    <td width="30%" align="right">อีเมล์ :</td>
                                    <td width="67%"><input name="txtEmail" type="text" class="txtbox" id="txtEmail" value="<?=$resultUser["Email"];?>" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">ยืนยันอีเมล์ :</td>
                                    <td><input name="txtEmailCon" type="text" class="txtbox" id="txtEmailCon" value="<?=$resultUser["Email"];?>" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">รหัสผ่าน :</td>
                                    <td><input name="txtPass" type="password" class="txtbox" id="txtPass" value="<?=$resultUser["Password"];?>" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">ยืนยันรหัสผ่าน :</td>
                                    <td><input name="txtPassCon" type="password" class="txtbox" id="txtPassCon" value="<?=$resultUser["Password"];?>" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">ชื่อ - นามสกุล :</td>
                                    <td><input name="txtName" type="text" class="txtbox" id="txtName" value="<?=$resultUser["Name"];?>" size="15" maxlength="255">
                                      - 
                                      <input name="txtLastName" type="text" class="txtbox" id="txtLastName" value="<?=$resultUser["LastName"];?>" size="15" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">เพศ :</td>
                                    <td><input name="rdoGender" type="radio" value="M" <?if($resultUser["Gender"]=="M"){?>checked<?}?>>
                                      ชาย 
                                      <input type="radio" name="rdoGender" value="F" <?if($resultUser["Gender"]=="F"){?>checked<?}?>>
                                      หญิง <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right" valign="top">ที่อยู่ :</td>
                                    <td> <textarea name="txtAddress" cols="40" rows="5" class="txtbox" id="txtAddress"><?=$resultUser["Address"];?></textarea> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">จังหวัด</td>
                                    <td><input name="txtProvince" type="text" class="txtbox" id="txtTel4" value="<?=$resultUser["Province"];?>" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">รหัสไปรษณีย์</td>
                                    <td><input name="txtZipCode" type="text" class="txtbox" id="txtTel3" value="<?=$resultUser["ZipCode"];?>" size="5" maxlength="5"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">หมายเลขโทรศัพท์</td>
                                    <td><input name="txtTel" type="text" class="txtbox" id="txtTel" value="<?=$resultUser["Tel"];?>" maxlength="255"> 
                                      <font color="#FF0000">*</font></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td align="right">หมายเลขโทรสาร</td>
                                    <td><input name="txtFax" type="text" class="txtbox" id="txtFax" value="<?=$resultUser["Fax"];?>" maxlength="255"></td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>
                                  <tr> 
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td><input name="Submit" type="submit" class="button" value="ตกลง"> 
                                      <input name="Reset" type="reset" class="button" id="Reset" value="เขียนใหม่"></td>
                                  </tr>
                                </table></td>
                            </tr>
                            <tr> 
                              <td width="466"><hr align="center" width="98%" color="#f2f2f6"></td>
                            </tr>
                          </table>
                        </form>
                        <p class="style59">&nbsp;</p>
                        <p class="style59">&nbsp;</p>
                        <p class="style59">&nbsp;</p></td>
                    </tr>
                  </table></td>
                <td width="20%" valign="top">&nbsp;</td>
              </tr>
              <tr> 
                <td colspan="3" valign="top">&nbsp;</td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
		<!-- InstanceEndEditable --></td>
        <td bgcolor="#d0d2d5">&nbsp;</td>
      </tr>
    </table>
      <table width="900" height="135" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td valign="top" bgcolor="#d0d2d5"><!-- InstanceBeginEditable name="EditRegion5" -->
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
          <!-- InstanceEndEditable --></td>
        </tr>
      </table>
    <span class="style1">©<span class="style2"> 2012-อีบุ๊ค.co.cc ,WebDesign by Apichai</span></span>J<br /></td>
  </tr>
</table>
<map name="Map" id="Map"><area shape="rect" coords="3,3,120,40" href="#" target="_top" />
</map>
<map name="Map2" id="Map2">
<area shape="poly" coords="200,96,199,124,172,118,124,143,32,127,16,114,11,48,13,3,50,9,79,11,107,18,178,-2,203,27,199,48,198,66,203,79" href="../index.php" />
</map>
<map name="Map3" id="Map3">
  <area shape="rect" coords="16,4,87,41" href="../page.html" />
<area shape="rect" coords="98,4,173,41" href="../airport.html" />
<area shape="rect" coords="188,4,280,40" href="../topup.html" />
<area shape="rect" coords="301,4,392,40" href="../sitemap.html" />
<area shape="rect" coords="406,3,472,40" href="#" />
<area shape="rect" coords="477,6,479,9" href="#" /><area shape="rect" coords="479,2,480,11" href="#" />
</map>
<map name="Map4" id="Map4"><area shape="rect" coords="10,4,108,38" href="../topup.html" />
</map></body>
<!-- InstanceEnd --></html>
